<template>
    <header>
        <van-nav-bar title="我的收藏" left-text="返回" left-arrow @click-left="onClickLeft" />
    </header>
    <main>
        <div class="wrap">
            <EssayList class="content-wrap" @click="goTO(i.id)" v-for="i in dataArr.arr" :i="i" />
        </div>
    </main>
</template>

<script setup>
import { getUserData } from "@/fun/fun";
import axios from "axios";
import { getUserMsg, getEssayDetailed } from "@/api/api";
import { reactive, ref, defineComponent } from "vue";
import { useRouter } from "vue-router";
import EssayList from "@/components/EssayList.vue";
// 组件
defineComponent({ EssayList });
let router = useRouter();
let userData = reactive({ obj: {} });
let dataIdArr = reactive({ arr: [] });
let dataArr = reactive({ arr: [] });
// 初始化用户数据
let fun = async () => {
    let getUserDataApi = () => {
        return axios(getUserMsg(getUserData()));
    };
    await getUserDataApi().then(({ data }) => {
        userData.obj = data[0];
        dataIdArr.arr = userData.obj.collect;
    });
    let essayDataApi = () => {
        dataIdArr.arr.forEach((i) => {
            axios(getEssayDetailed(i)).then(({ data }) => {
                dataArr.arr.push(data.data[0]);
            });
        });
    };
    essayDataApi();
};
fun();
const onClickLeft = () => router.go(-1);
// 进入内容详细
let goTO = (id) => {
    router.push({ name: "articleDetails", query: { id } });
};
</script>

<style lang="scss" scoped>
main {
    background-color: #f8f8f8;
    min-height: 91vh;
    .wrap {
        padding: 0 3vw 55px;
        overflow: hidden;
        .content-wrap {
            margin-top: 10px;
            border-radius: 10px;
            background-color: #fff;
            padding: 10px;
            box-sizing: border-box;
            width: 100%;
            height: 100px;
            display: flex;
        }
    }
}
</style>
